﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using SYS.Basic;

using ExpertMIS.Brokers;
using ExpertMIS.Entities;
using System.Collections;


namespace ExpertMIS.Brokers
{
    public class ForumBroker: ExpertMISBaseBroker
    {
        #region Private Methods

        private object UpdateYafForumEntity(IEntity entity)
        {
            return SqlMap.Update("UpdateYafForumEntity", entity);
        }

        private object InsertYafForumEntity(IEntity entity)
        {
            return SqlMap.Insert("InsertYafForumEntity", entity);
        }

        private object DeleteYafForumEntity(IEntity entity)
        {
            return SqlMap.Delete("DeleteYafForumEntity", entity);
        }

        #endregion

        #region Override Methods

        protected override IEntity ProcessGetEntity(System.Collections.Hashtable keys)
        {
			if (!keys.Contains("OID")) throw new Exception("invalid request parameters.");
            return SqlMap.QueryForObject<IEntity>("SelectYafForumEntityByOID", keys["OID"] as string);
        }

        protected override bool ProcessSaveEntity(IEntity entity, Hashtable request)
        {
            if (entity.EntityState == EntityState.New)
            {
                InsertYafForumEntity(entity);
                entity.EntityState = EntityState.Old;
            }
            else
            {
                UpdateYafForumEntity(entity);
            }

            return true;
        }

        protected override IEntity ProcessNewEntity()
        {
            ForumEntity entity = new ForumEntity();
			
			// initial entity object

            return entity;
        }

        protected override bool ProcessRemoveEntity(IEntity entity, Hashtable request)
        {
            try
            {
                DeleteYafForumEntity(entity);
                return true;
            }
            catch
            {
                return false;
            }
        }
        #endregion
    }
}
